package com.after.saas.file.handler;

import com.after.saas.file.constants.MedalTitleEnum;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @Description
 * @Classname LevelOne
 * @Author hjchen
 * @Version V1.0.0
 * @Since 1.0
 * @Date 2023/4/7 15:40
 */

@Component
public class SilverLevel extends MedalLevel {

    private final MedalFactory medalFactory;

    public SilverLevel(MedalFactory medalFactory) {
        this.medalFactory = medalFactory;
    }

    @Override
    public MedalTitleEnum getMedalEnum() {
        return MedalTitleEnum.SILVER;
    }

    @Override
    public MedalRecord handleRequest(BigDecimal points) {
        if (preRequest(points)) {
            return medalFactory.generateHandler(getMedalEnum().name()).saveMedalRecord(points);
        } else {
            MedalLevel medalLevel = getNext();
            if (medalLevel != null) {
                return medalLevel.handleRequest(points);
            }
        }
        return null;
    }
}
